<?php
require_once 'fenbuMemConnect.php';

class ActionMemcache extends FenbuMemConnect
{
    public $mem;
    function __construct()
    {
        parent::__construct();   
    }
    
    private function Connect($str)
    {
        $connect_host = $this->consistentHash->find($str); //memcache连接的服务器地址

        if(strpos($connect_host,'#')) //这边以#作为虚拟节点标记
        {
            //进行字符串截取，获取#号之前的host地址
            $connect_host = strstr($connect_host, '#' , true);
        }
        $this->mem = new Memcache();
        $te = $this->mem->connect($connect_host,11211);
        var_dump($te);
        echo "connect host:".$connect_host."<br />";
    }
    
    function SET($key,$value,$flag = null, $expire = null)
    {
        $this->Connect($key);
   
        return $this->mem->set($key, $value , $flag , $expire);
    }
    
    function GET($key)
    {
       $this->Connect($key);
       return $this->mem->get($key);
    }    
}

